package com.bweab.controll.userstbcontrol;

import com.bweab.pojo.UsersTb;
import com.bweab.service.api.UsersTbServiceInterface;
import com.bweab.service.impl.UsersTbServiceInterfaceImpl;
import com.bweab.util.JSONResult;
import com.bweab.util.JSONStats;
import com.bweab.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/regist")
public class Regist extends HttpServlet {
    JSONResult jsonResult=new JSONResult();
    UsersTbServiceInterface userService = new UsersTbServiceInterfaceImpl();//调用user服务端接口
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端传来的数据
        //获取用户名
        String username = req.getParameter("username");
        //获取密码
        String userpassword = req.getParameter("userPassword");
        //获取性别
        String userSex = req.getParameter("userSex");
        //获取学号
        String userXh = req.getParameter("userXh");
        //获取手机号
        String userPhone = req.getParameter("userPhone");
        System.out.println(username+"\n"+userpassword+"\n"+userSex+"\n"+userXh+"\n"+userPhone);
        //调用服务层接口
        int result1= userService.regist(username,userpassword,userSex,userXh,userPhone);
        if(result1==0){
            //注册失败
            jsonResult.setStatusCode(JSONStats.REGIST_ERROR.getStatusCode());
            jsonResult.setMessage(JSONStats.REGIST_ERROR.getMessage());
            WebUtil.writeJson(resp,jsonResult);

        }else if(result1 >0){
            //注册成功
            jsonResult.setStatusCode(JSONStats.REGIST_SUCCESS.getStatusCode());
            jsonResult.setMessage(JSONStats.REGIST_SUCCESS.getMessage());
            WebUtil.writeJson(resp,jsonResult);

        }




    }
}
